#ifndef __AMR2WAVCODE_H__
#define __AMR2WAVCODE_H__

#include "g_1903.h"
#include "g_system.h"
#include "interf_dec.h"

typedef struct
{
    short nFormatTag;
    short nChannels;
    int nSamplesPerSec;
    int nAvgBytesPerSec;
    short nBlockAlign;
    short nBitsPerSample;
    short nExSize;
}WAVEFORMATX;
 
/*RIFF区块*/
typedef struct
{
    char chRiffID[4];           /*'RIFF' (0x52494646)*/
    int  nRiffSize;             /*Size是整个文件的长度减去ID和Size的长度 file-8*/
    char chRiffFormat[4];       /*'WAVE'(0x57415645)*/
}RIFFHEADER;

/*FORMAT区块*/
typedef struct
{
    short nFormatTag;           /*音频格式*/
    short nChannels;            /*声道数*/
    int nSamplesPerSec;         /*采样率*/
    int nAvgBytesPerSec;        /*每秒数据字节数*/
    short nBlockAlign;          /*数据库对齐*/
    short nBitsPerSample;       /*采样位数*/
}WAVEFORMAT;
typedef struct
{
    char chFmtID[4];           /*'fmt ' (0x666D7420)*/
    int  nFmtSize;             /*16 Size表示该区块数据的长度（不包含ID和Size的长度）*/
    WAVEFORMAT wf;             /*wav格式结构体定义*/
}FMTBLOCK;

/*DATA区块*/
typedef struct
{
    char chChunkID[4];          /*'data' (0x64617461)*/
    int  nChunkSize;            /*Size表示音频数据的长度，N = ByteRate * seconds*/
}XCHUNKHEADER;

int32_t caclAMRFrameSize(uint8_t frameHeader);
int32_t DecodeAMRFileToWAVEFile(uint8_t *amrbuf, uint8_t* wavebuf);
int32_t* DecodeAMRFileToWAVEFilePacket(int32_t * destate,uint8_t *amrbuf, uint8_t* wavebuf,uint8_t isend);

#endif
